﻿using EFCore.Models;
using Microsoft.EntityFrameworkCore;
using SIService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SService
{
    public class OrganizationalStructureS : OrganizationalStructureSI
    {
        private readonly WmssystemContext myDb;

        public OrganizationalStructureS(WmssystemContext myDb)
        {
            this.myDb = myDb;
        }

        public Task<List<Sys_OrganizationalStructure>> Erji(int pid)
        {
            return  myDb.Sys_OrganizationalStructure.Where(c => c.O_SSortingOrder == pid).ToListAsync();
        }
        //模糊查询
        public Task<List<Sys_OrganizationalStructure>> FenYe(string Key = null, string Status = null)
        {
            var query = myDb.Sys_OrganizationalStructure.AsQueryable();

            // 根据条件进行查询
            if (!string.IsNullOrEmpty(Key))
            {
                query = query.Where(c => c.O_SOrganizationName.Contains(Key) || c.O_SOrganizationCode.Contains(Key));
            }
            if (!string.IsNullOrEmpty(Status))
            {
                query = query.Where(c => c.O_SStatus.Contains(Status));
            }
            // 查询
            return query.ToListAsync();
        }

        public Task<List<Sys_OrganizationalStructure>> YiJi()
        {
            return myDb.Sys_OrganizationalStructure.Where(c => c.O_SSortingOrder == 0).ToListAsync();
        }
    }
}
